package ssm.blog.controller.admin;

import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import ssm.blog.service.ContactMsgService;
import ssm.blog.util.ResponseUtil;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * @program: lyon
 * @description: 我的消息控制层
 * @author: Lyon
 * @create: 2018-06-06 22:51
 **/
@Controller
@RequestMapping("/admin")
public class AdminContactMsgController {
    @Resource
    ContactMsgService contactMsgService;
    @RequestMapping("/contactMsgDele")
    String blogTypeDele(HttpServletResponse response, Integer id) throws Exception {
        int resultRows=contactMsgService.dele(id);
        JSONObject result=new JSONObject();
        if(resultRows>0){
            result.put("success",true);
        }else {
            result.put("success",false);
        }
        ResponseUtil.write(response,result);
        return null;
    }

    @RequestMapping("/contactMsgsDele")
    String blogTypesDele(HttpServletResponse response,String ids)throws Exception{
        //分割得到所有ID
        String[] IDS_str=ids.split(",");
        //转化为Integer数组
        List<Integer> IDS_INT=new ArrayList<>();
        for(String i:IDS_str) {
            IDS_INT.add(Integer.valueOf(i));
        }
        //删除
        int resultRows=contactMsgService.deles(IDS_INT);
        //返回删除结果
        JSONObject result=new JSONObject();
        if(resultRows>0){
            result.put("success",true);
        }else {
            result.put("success",false);
        }
        ResponseUtil.write(response,result);
        return null;
    }
}
